package com.ledi.guns.modular.ledipay.controller;

import io.swagger.annotations.Api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.ledi.guns.common.persistence.model.vo.RegionVo;
import com.ledi.guns.core.base.controller.BaseController;
import com.ledi.guns.core.base.tips.SuccessTip;
import com.ledi.guns.modular.ledipay.controller.req.region.QueryRegion;
import com.ledi.guns.modular.ledipay.service.impl.RegionServiceImpl;

@Api
@RestController
@RequestMapping("/region")
public class RegionController extends BaseController {

	@Autowired
	private RegionServiceImpl regionService;

	/**
	 * @api {GET} /region/province 获取省
	 * @apiGroup region
	 * @apiName province
	 * @apiVersion 1.0.0
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "data": {
	 *                    "code": "110000",
	 *                    "name": "北京市"
	 *                    },
	 *                    "message": "成功"
	 *                    }
	 */
	@RequestMapping(value = "/province", method = RequestMethod.GET)
	public Object getProvince() {

		List<RegionVo> regionVos = regionService.getProvince();
		return SuccessTip.buildSuccess(regionVos);
	}

	/**
	 * @api {POST} /region/city 获取市
	 * @apiGroup region
	 * @apiName city
	 * @apiParam {String} code 上级城市编码
	 * @apiVersion 1.0.0
	 * @apiParamExample {json} Request-Example:
	 *                  {
	 *                  "code": "13546"
	 *                  }
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "data": {
	 *                    "code": "110000",
	 *                    "name": "北京市"
	 *                    },
	 *                    "message": "成功"
	 *                    }
	 */

	@RequestMapping(value = "/city", method = RequestMethod.POST)
	public Object getCity(@RequestBody QueryRegion queryRegion) {

		List<RegionVo> regionVos = regionService.getCity(queryRegion);
		return SuccessTip.buildSuccess(regionVos);
	}

	/**
	 * @api {POST} /region/area 获取区
	 * @apiGroup region
	 * @apiName area
	 * @apiParam {String} code 上级城市编码
	 * @apiVersion 1.0.0
	 * @apiParamExample {json} Request-Example:
	 *                  {
	 *                  "code": "13546"
	 *                  }
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "data": {
	 *                    "code": "110000",
	 *                    "name": "北京市"
	 *                    },
	 *                    "message": "成功"
	 *                    }
	 */

	@RequestMapping(value = "/area", method = RequestMethod.POST)
	public Object getArea(@RequestBody QueryRegion queryRegion) {

		List<RegionVo> regionVos = regionService.getArea(queryRegion);
		return SuccessTip.buildSuccess(regionVos);
	}

	/**
	 * @api {POST} /region/getNameByCode 通过code获取名称
	 * @apiGroup region
	 * @apiName getNameByCode
	 * @apiParam {String} code 上级城市编码
	 * @apiVersion 1.0.0
	 * @apiParamExample {json} Request-Example:
	 *                  {
	 *                  "code": "13546"
	 *                  }
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "data": {
	 *                    "丰南区",
	 *                    },
	 *                    "message": "成功"
	 *                    }
	 */

	@RequestMapping(value = "/getNameByCode", method = RequestMethod.POST)
	@ResponseBody
	public Object getNameByCode(@RequestParam String code) {

		String name = regionService.getNameByCode(code);
		return SuccessTip.buildSuccess(name);
	}

	/**
	 * @api {POST} /region/getCodeByName 通过名称获取
	 * @apiGroup region
	 * @apiName getCodeByName
	 * @apiParam {String} code 上级城市编码
	 * @apiVersion 1.0.0
	 * @apiParamExample {json} Request-Example:
	 *                  {
	 *                  "name": "13546"
	 *                  }
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "data": {
	 *                    "code":"123154",
	 *                    },
	 *                    "message": "成功"
	 *                    }
	 */

	@RequestMapping(value = "/getCodeByName", method = RequestMethod.POST)
	@ResponseBody
	public Object getCodeByName(@RequestParam String name) {

		return SuccessTip.buildSuccess(regionService.getCodeByName(name));
	}
}
